{extend name="Public:base" /}
   
{block name="body"}
<div class="page " id="topicaddhtml" style="background:#fff;">
<header class="aui-bar  aui-bar-nav aui-border-b  aui-bar-light" id="header">

   <a class="aui-pull-left aui-btn aui-text-warning external" href="{:es_url('Wap/groupinfo',array('id'=>$id))}"   id="zuoce">
        <span class="icon  icon-xiangzuojiantou "></span>
    </a>
    <div class="aui-title" id="headername">添加帖子</div>
   <a class="aui-pull-right  " id="youce" href="javascript:;" onclick="topicadd()">
        <span class="aui-text-warning">发表</span>
    </a>

</header>
<style>
#wrap{white-space:normal; width:100%; }
</style>
<div class="content">
<div class="aui-padded-15">

<input type="hidden" id="groupid" name="groupid" value="{$id}" />
<textarea style="border:0;"  placeholder="标题(最多36个字)" rows="3" id="title" onclick="showorhide(1)"  onkeyup="textjq(this,36)" ></textarea>
</div>
<div class="aui-padded-15 aui-border-t">


<div contenteditable="true" id="content" onclick="showorhide(2)" placeholder="请输入帖子正文" style="margin-bottom:2.25rem;">请输入帖子正文</div>
</div>

  

  </div>
  <footer class="aui-bar aui-bar-tab " id="footer" style="background:#fafafa">
<div class="dpui-border-t">

<div id="imgsrc" class="aui-pull-left aui-margin-l-15">

</div>
    </div>
</footer>

   
<script type="text/javascript">

$('#topicaddhtml').on('pageInit', function(e,id,page) {
	



	
});

function topicadd(){

var title = $('#title').val();
var content = $('#content').html();
var groupid = $('#groupid').val();



if (content==''||title=='') {
	  layer.msg('请将信息填写完整后提交');
        
   
        return;
    }
var data={content:content,id:groupid,title:title};
var url = "{:es_url('Wap/topicpost')}";


$.post(url, data, function(ret){
	if (ret.code==0) {

		if(ret.data.status=='error'){
			  layer.msg(ret.data.msg);
		}else{
			  layer.msg(ret.data.msg,function(){location.href="{:es_url('Wap/ucenter',array('id'=>$id))}";});
			  
			  
			  
			
			
			}
	}
});

}
function showorhide(id){

if(id==1){
if(!$('#footer').hasClass('aui-hide')){
$('#footer').addClass('aui-hide');
}
}else{

if($('#content').html()==$('#content').attr('placeholder')){

$('#content').html('');
}


if($('#footer').hasClass('aui-hide')){
$('#footer').removeClass('aui-hide');
}
}


}
$('#topicaddhtml').on('pageInit', function(e,id,page) {
	
	


	
});
</script>
  </div>
 {/block}
 
 
 {block name="js"}
 <script src="__PUBLIC__/js/jquery-1.9.1.min.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
 <link rel="stylesheet" href="__PUBLIC__/js/webuploader/webuploader.css" />
<script src="__PUBLIC__/js/webuploader/webuploader.js"></script>

<style>

.webuploader-pick{
background:rgba(0,0,0,0);
}
</style>
<script type="text/javascript">
function textjq(obj, maxlimit){
    if ($(obj).val().length > maxlimit){  
   $(obj).val($(obj).val().substr(0, maxlimit));  
   layer.msg('已超出限制字数');
  }
   }
var uploader = WebUploader.create({
	auto: true,
    swf: '__PUBLIC__/Uploader.swf',
    pick: {
        id: '#imgsrc',
        label: '<i  style="color:#000;font-size:1.25rem" class="icon icon-tianjia"></i>'
    },
    chunked: false,
    chunkSize: 512 * 1024,
    server: "{:es_url('Wap/picupload')}",
    // 禁掉全局的拖拽功能。这样不会出现图片拖进页面的时候，把图片打开。
    disableGlobalDnd: true,
    fileNumLimit: 20,
    fileSizeLimit: 200 * 1024 * 1024,    // 200 M
    fileSingleSizeLimit: 50 * 1024 * 1024,    // 50 M
    accept: {
        title: 'Images',
        extensions: 'gif,jpg,jpeg,bmp,png',
        mimeTypes: 'image/jpg,image/jpeg,image/png'
    }
  
});
uploader.on( 'uploadSuccess', function( file,data ) {
 if(data.id>0){
	 var range = window.getSelection().getRangeAt(0);//找到焦点位置
	
	 var span = document.createElement('div');
     span.innerHTML = '<br /><img src="'+headpath+'" /><br />';
     range.insertNode(span);
	 
 }
  
});

uploader.on( 'uploadError', function( file ) {
	  layer.msg('上传出错');
});

uploader.on( 'uploadComplete', function( file ) {
  
});
</script>
 {/block}